﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ParsecParser;
using ParsecParser.Data;
using ParsecParser.Helpers;
using ParsecParser.Display;

namespace ParsecClient.Classes
{
    [Serializable]
    public class ArchivedRaidFightMember
    {
        public string CharacterName { get; set; }
        public long DamageOut { get; set; }
        public long DamageIn { get; set; }
        public long HealOut { get; set; }
        public long EffectiveHealOut { get; set; }
        public long HealIn { get; set; }
        public long Threat { get; set; }
        public string ThreatList { get; set; }
        public double AbsorbShieldValue { get; set; }
        public int AbsorbShieldsCast { get; set; }
        public DateTime StartCombat { get; set; }
        public DateTime? EndCombat { get; set; }
        public int RaidEncounterId { get; set; }
        public int RaidEncounterMode { get; set; }
        public int RaidEncounterPlayers { get; set; }
        public long CombatTicks { get; set; }
        public ArchivedRaidFightMember()
        {
        }
        public CombatStatistics ConvertToCombatStatistics()
        {
            return ArchivedRaidFightMember.ConvertToCombatStatistics(this);
        }
        public static CombatStatistics ConvertToCombatStatistics(ArchivedRaidFightMember source)
        {
            return new CombatStatistics(source.ThreatList.ConvertToParticipantList() ?? new Dictionary<string, CombatLogParticipant>())
            {
                CharacterName = source.CharacterName,
                CombatTicks = source.CombatTicks,
                DamageIn = source.DamageIn,
                DamageOut = source.DamageOut,
                EffectiveHealOut = source.EffectiveHealOut,
                EndCombat = source.EndCombat,
                RaidEncounterDetail = new RaidEncounterDetails() { 
                    RaidEncounterId = source.RaidEncounterId, 
                    Mode = (ParsecParser.RaidEncounterDetails.DifficultyMode)source.RaidEncounterMode,
                    Players = (ParsecParser.RaidEncounterDetails.PlayerCount)source.RaidEncounterPlayers },
                HealIn = source.HealIn,
                HealOut = source.HealOut,
                StartCombat = source.StartCombat,
                Threat = source.Threat,
                CombatTimeSpan = new TimeSpan(source.CombatTicks),
                AbsorbShieldValue = source.AbsorbShieldValue,
                AbsorbShieldsCast = source.AbsorbShieldsCast                
            };
        }
        public static ArchivedRaidFightMember ConvertToArchivedRaidFightItem(CombatStatistics source)
        {
            return new ArchivedRaidFightMember()
            {
                CharacterName = source.CharacterName,
                CombatTicks = source.CombatTicks,
                DamageIn = source.DamageIn,
                DamageOut = source.DamageOut,
                EffectiveHealOut = source.EffectiveHealOut,
                EndCombat = source.EndCombat,
                RaidEncounterId = source.RaidEncounterDetail.RaidEncounterId,
                RaidEncounterMode = (int)source.RaidEncounterDetail.Mode,
                RaidEncounterPlayers = (int)source.RaidEncounterDetail.Players,
                HealIn = source.HealIn,
                HealOut = source.HealOut,
                StartCombat = source.StartCombat,
                Threat = source.Threat,
                ThreatList = source.GetParticipantList().Where(x => x.IsEnemy && !x.IsPlayer).ConvertThreatListToString(),
                AbsorbShieldValue = source.AbsorbShieldValue,
                AbsorbShieldsCast = source.AbsorbShieldsCast
            };
        }
    }
}
